﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TaoPortal.Areas.Admin.Models;

namespace TaoPortal.Areas.Admin.Controllers
{
    public class SimplePageController : BaseController
    {
        //
        // GET: /SimplePage/

        public ActionResult Index()
        {
            ViewBag.NavTitle = "单页";
            return View(new SimplePageModel());
        }

        [HttpPost]
        public ActionResult AjaxGetList(SimplePageModel model)
        {
            var data = model.GetSimplePageList();
            return Content(SerializeJson(new { results = data.TotalItemCount, rows = data }));
        }

        public ActionResult AddPage()
        {
            return PartialView(new SimplePageModel());
        }

        [HttpPost]
        [ValidateInput(false)]
        public ActionResult AddPage(SimplePageModel model)
        {
            if (ModelState.IsValid)
            {
                model.Add();
                //return JavaScript("alert('提交成功')");
                return Content("<script>parent.SubmitSuccess()</script>");
            }
            else
            {
                return PartialView(model);
            }
        }

        public ActionResult EditPage(string id)
        {
            SimplePageModel model = new SimplePageModel();
            model.InitSimplePage(id);
            return PartialView(model);
        }

        [HttpPost]
        [ValidateInput(false)]
        public ActionResult EditPage(SimplePageModel model)
        {
            if (ModelState.IsValid)
            {
                model.Edit();
                return Content("<script>parent.SubmitSuccess()</script>");
            }
            else
            {
                return PartialView(model);
            }
        }
        [HttpPost]
        public ActionResult DeletePage(string id)
        {
            SimplePageModel model = new SimplePageModel();
            model.DeleteSimplePage(id);
            return Json(new { result = true });
        }
    }
}
